package com.inossem.warehousestorage_inossem.utils;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import com.google.gson.Gson;
import com.inossem.utils.listener.NoDoubleClickListener;
import com.inossem.utils.log.LogUtils;
import com.inossem.warehousestorage_inossem.R;
import com.inossem.warehousestorage_inossem.adapter.OverviewAdapter;
import com.inossem.warehousestorage_inossem.bean.common.GetOperatorBean;
import com.inossem.warehousestorage_inossem.bean.common.GetOperatorGroupBean;
import com.inossem.warehousestorage_inossem.bean.refundStorage.BatchSpecListBean;
import com.inossem.warehousestorage_inossem.bean.refundStorage.RefundStorageAddOperatorUserGroupBean;
import com.inossem.warehousestorage_inossem.bean.refundStorage.RefundStorageNewBatchBean;
import com.inossem.warehousestorage_inossem.bean.refundStorage.RefundStorageOperatorBean;
import com.inossem.warehousestorage_inossem.bean.refundStorage.RefundStoragePickingConfirmRequestBean;
import com.inossem.warehousestorage_inossem.bean.refundStorage.RefundStoragePickingOverviewBean;
import com.inossem.warehousestorage_inossem.bean.refundStorage.RefundStorageReservedConfirmRequestBean;
import com.inossem.warehousestorage_inossem.bean.refundStorage.RefundStorageReservedOverviewBean;
import com.inossem.warehousestorage_inossem.bean.refundStorage.RefundStorageSaleConfirmRequestBean;
import com.inossem.warehousestorage_inossem.bean.refundStorage.RefundStorageSaleOverviewBean;
import com.inossem.warehousestorage_inossem.dialog.DialogUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by leij on 2017/9/5.
 */

public class RefundStorageUtils {

    //获取领料退库信息
    public static RefundStoragePickingOverviewBean getRefundStoragePickingOverviewBean(Context context) {
        String json = SPUtils.getPickingRefundStorageInformation(context);
        if (TextUtils.isEmpty(json)) {
            return new RefundStoragePickingOverviewBean();
        } else {
            Gson gson = new Gson();
            return gson.fromJson(json, RefundStoragePickingOverviewBean.class);
        }
    }

    //获取销售退库信息
    public static RefundStorageSaleOverviewBean getRefundStorageSaleOverviewBean(Context context) {
        String json = SPUtils.getSaleRefundStorageInformation(context);
        if (TextUtils.isEmpty(json)) {
            return new RefundStorageSaleOverviewBean();
        } else {
            Gson gson = new Gson();
            return gson.fromJson(json, RefundStorageSaleOverviewBean.class);
        }
    }

    //获取预留退库信息
    public static RefundStorageReservedOverviewBean getRefundStorageReservedOverviewBean(Context context) {
        String json = SPUtils.getReservedRefundStorageInformation(context);
        if (TextUtils.isEmpty(json)) {
            return new RefundStorageReservedOverviewBean();
        } else {
            Gson gson = new Gson();
            return gson.fromJson(json, RefundStorageReservedOverviewBean.class);
        }
    }

    //保存领料退库信息
    public static void savePickingRefundStorageOverviewBean(Context context, RefundStoragePickingOverviewBean refundStoragePickingOverviewBean) {
        Gson gson = new Gson();
        SPUtils.savePickingRefundStorageInformation(context, gson.toJson(refundStoragePickingOverviewBean, RefundStoragePickingOverviewBean.class));
    }

    //保存销售退库信息
    public static void saveSaleRefundStorageOverviewBean(Context context, RefundStorageSaleOverviewBean refundStorageSaleOverviewBean) {
        Gson gson = new Gson();
        SPUtils.saveSaleRefundStorageInformation(context, gson.toJson(refundStorageSaleOverviewBean, RefundStorageSaleOverviewBean.class));
    }

    //保存预留退库信息
    public static void saveReservedRefundStorageOverviewBean(Context context, RefundStorageReservedOverviewBean refundStorageReservedOverviewBean) {
        Gson gson = new Gson();
        SPUtils.saveReservedRefundStorageInformation(context, gson.toJson(refundStorageReservedOverviewBean, RefundStorageReservedOverviewBean.class));
    }

    //过滤领料退库货品列表信息
    public static List<RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean> getPickingRefundStorageMaterielList(Context context, String materiel) {
        List<RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean> refundStorageList = new ArrayList<>();
        List<RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean> allRefundStorageList = getRefundStoragePickingOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < allRefundStorageList.size(); i++) {
            RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean item = allRefundStorageList.get(i);
            if (item.getMat_code().contains(materiel) || item.getMat_name().contains(materiel)) {
                refundStorageList.add(item);
                continue;
            }
        }
        return refundStorageList;
    }

    //过滤销售退库货品列表信息
    public static List<RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean> getSaleRefundStorageMaterielList(Context context, String materiel) {
        List<RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean> refundStorageList = new ArrayList<>();
        List<RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean> allRefundStorageList = getRefundStorageSaleOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < allRefundStorageList.size(); i++) {
            RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean item = allRefundStorageList.get(i);
            if (item.getMat_code().contains(materiel) || item.getMat_name().contains(materiel)) {
                refundStorageList.add(item);
                continue;
            }
        }
        return refundStorageList;
    }

    //过滤预留退库货品列表信息
    public static List<RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean> getReservedRefundStorageMaterielList(Context context, String materiel) {
        List<RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean> refundStorageList = new ArrayList<>();
        List<RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean> allRefundStorageList = getRefundStorageReservedOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < allRefundStorageList.size(); i++) {
            RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean item = allRefundStorageList.get(i);
            if (item.getMat_code().contains(materiel) || item.getMat_name().contains(materiel)) {
                refundStorageList.add(item);
                continue;
            }
        }
        return refundStorageList;
    }

    //检查领料退库列表是否至少填写一项
    public static int getPickingRefundStorageNumber(Context context) {
        int result = 0;
        List<RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean> materielList = getRefundStoragePickingOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < materielList.size(); i++) {
            RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getRefundNumber()) && Float.parseFloat(materielItem.getRefundNumber()) > 0) {
                result = result + 1;
            }
        }
        return result;
    }

    //检查销售退库列表是否至少填写一项
    public static int getSaleRefundStorageNumber(Context context) {
        int result = 0;
        List<RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean> materielList = getRefundStorageSaleOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < materielList.size(); i++) {
            RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getRefundNumber()) && Float.parseFloat(materielItem.getRefundNumber()) > 0 && !context.getResources().getString(R.string.activity_refund_storage_sale_materiel_detail_choose_batch_number).equals(materielItem.getBatch())) {
                result = result + 1;
            }
        }
        return result;
    }

    //检查预留退库列表是否至少填写一项
    public static int getReservedRefundStorageNumber(Context context) {
        int result = 0;
        List<RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean> materielList = getRefundStorageReservedOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < materielList.size(); i++) {
            RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getRefundNumber()) && Float.parseFloat(materielItem.getRefundNumber()) > 0 && !context.getResources().getString(R.string.activity_refund_storage_sale_materiel_detail_choose_batch_number).equals(materielItem.getBatch())) {
                result = result + 1;
            }
        }
        return result;
    }

    //创建查看批次特性
    public static void createTextView(Context context, ViewGroup viewGroup, String name, String text) {
        createTextView(context, viewGroup, name, text, true);
    }

    //创建查看批次特性
    public static void createTextView(Context context, ViewGroup viewGroup, String name, String text, boolean hasLine) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.view_refund_storage_textview, null);
        TextView nameTextView = (TextView) view.findViewById(R.id.name);
        TextView textTextView = (TextView) view.findViewById(R.id.text);
        View line1 = view.findViewById(R.id.line1);
        nameTextView.setText(name);
        textTextView.setText(text);
        if (hasLine) {
            line1.setVisibility(View.VISIBLE);
        } else {
            line1.setVisibility(View.GONE);
        }
        viewGroup.addView(view);
    }

    //更新领料退库备注
    public static void updatePickingRefundStorageRemark(Context context, String remark) {
        RefundStoragePickingOverviewBean bean = getRefundStoragePickingOverviewBean(context);
        bean.getBody().setRemark(remark);
        savePickingRefundStorageOverviewBean(context, bean);
    }

    //更新销售退库备注
    public static void updateSaleRefundStorageRemark(Context context, String remark) {
        RefundStorageSaleOverviewBean bean = getRefundStorageSaleOverviewBean(context);
        bean.getBody().setRemark(remark);
        saveSaleRefundStorageOverviewBean(context, bean);
    }

    //更新预留退库备注
    public static void updateReservedRefundStorageRemark(Context context, String remark) {
        RefundStorageReservedOverviewBean bean = getRefundStorageReservedOverviewBean(context);
        bean.getBody().setRemark(remark);
        saveReservedRefundStorageOverviewBean(context, bean);
    }

    //更新领料退库行项目
    public static void updatePickingRefundStorageItem(Context context, RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean materielItem) {
        RefundStoragePickingOverviewBean bean = getRefundStoragePickingOverviewBean(context);
        List<RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean> pickingRefundstoragelist = bean.getBody().getItem_list();
        for (int i = 0; i < pickingRefundstoragelist.size(); i++) {
            RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean pickingRefundstorageItem = pickingRefundstoragelist.get(i);
            if (materielItem.getRid().equals(pickingRefundstorageItem.getRid())) {
                pickingRefundstoragelist.remove(pickingRefundstorageItem);
                pickingRefundstoragelist.add(i, materielItem);
                break;
            }
        }
//        bean.getData().setMaterielList(pickingRefundstoragelist);
        bean.getBody().setItem_list(pickingRefundstoragelist);
        savePickingRefundStorageOverviewBean(context, bean);
    }

    //更新销售退库行项目
    public static void updateSaleRefundStorageItem(Context context, RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean materielItem) {
        RefundStorageSaleOverviewBean bean = getRefundStorageSaleOverviewBean(context);
        List<RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean> saleRefundstoragelist = bean.getBody().getItem_list();
        for (int i = 0; i < saleRefundstoragelist.size(); i++) {
            RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean saleRefundstorageItem = saleRefundstoragelist.get(i);
            if (materielItem.getRid().equals(saleRefundstorageItem.getRid())) {
                saleRefundstoragelist.remove(saleRefundstorageItem);
                saleRefundstoragelist.add(i, materielItem);
                break;
            }
        }
        bean.getBody().setItem_list(saleRefundstoragelist);
        saveSaleRefundStorageOverviewBean(context, bean);
    }

    //更新预留退库行项目
    public static void updateReservedRefundStorageItem(Context context, RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean materielItem) {
        RefundStorageReservedOverviewBean bean = getRefundStorageReservedOverviewBean(context);
        List<RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean> saleRefundstoragelist = bean.getBody().getItem_list();
        for (int i = 0; i < saleRefundstoragelist.size(); i++) {
            RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean saleRefundstorageItem = saleRefundstoragelist.get(i);
            if (materielItem.getRid().equals(saleRefundstorageItem.getRid())) {
                saleRefundstoragelist.remove(saleRefundstorageItem);
                saleRefundstoragelist.add(i, materielItem);
                break;
            }
        }
        bean.getBody().setItem_list(saleRefundstoragelist);
        saveReservedRefundStorageOverviewBean(context, bean);
    }

    //通过物料编码获取领料退库第一个查询到的索引
    public static int getPickingIndexByMaterielCode(Context context, String materielCode) {
        List<RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean> list = getRefundStoragePickingOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getMat_code().equals(materielCode)) {
                return i;
            }
        }
        return -1;
    }

    //通过物料编码获取销售退库第一个查询到的索引
    public static int getSaleIndexByMaterielCode(Context context, String materielCode) {
        List<RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean> list = getRefundStorageSaleOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getMat_code().equals(materielCode)) {
                return i;
            }
        }
        return -1;
    }

    //通过物料编码获取预留退库第一个查询到的索引
    public static int getReservedIndexByMaterielCode(Context context, String materielCode) {
        List<RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean> list = getRefundStorageReservedOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getMat_code().equals(materielCode)) {
                return i;
            }
        }
        return -1;
    }

    //通过序号获取领料退库行项目
    public static RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean getPickingRefundStorageItemBySerial(Context context, String serial) {
        List<RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean> pickingRefundStorageItemList = getRefundStoragePickingOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < pickingRefundStorageItemList.size(); i++) {
            RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean item = pickingRefundStorageItemList.get(i);
            if (item.getRid().equals(serial)) {
                return item;
            }
        }
        return null;
    }

    //通过序号获取销售退库行项目
    public static RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean getSaleRefundStorageItemBySerial(Context context, String serial) {
        List<RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean> saleRefundStorageItemList = getRefundStorageSaleOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < saleRefundStorageItemList.size(); i++) {
            RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean item = saleRefundStorageItemList.get(i);
            if (item.getRid().equals(serial)) {
                return item;
            }
        }
        return null;
    }

    //通过序号获取预留退库行项目
    public static RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean getReservedRefundStorageItemBySerial(Context context, String serial) {
        List<RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean> saleRefundStorageItemList = getRefundStorageReservedOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < saleRefundStorageItemList.size(); i++) {
            RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean item = saleRefundStorageItemList.get(i);
            if (item.getRid().equals(serial)) {
                return item;
            }
        }
        return null;
    }

    //检查领料退库行项目是否填完
    public static boolean checkPickingItem(RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean pickingRefundStorageItem) {
        if (TextUtils.isEmpty(pickingRefundStorageItem.getRefundNumber())) {
            return false;
        } else {
            if (Double.parseDouble(pickingRefundStorageItem.getRefundNumber()) == 0) {
                return false;
            }
        }
        return true;
    }

    //检查销售退库行项目是否填完
    public static boolean checkSaleItem(RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean saleRefundStorageItem) {
        if (TextUtils.isEmpty(saleRefundStorageItem.getRefundNumber())) {
            return false;
        } else {
            if (Double.parseDouble(saleRefundStorageItem.getRefundNumber()) == 0) {
                return false;
            }
        }
        if (TextUtils.isEmpty(saleRefundStorageItem.getBatch())) {
            if (saleRefundStorageItem.getBatch_material_spec_list() == null || saleRefundStorageItem.getBatch_material_spec_list().isEmpty()) {
                return false;
            }
        }
        return true;
    }

    //检查销预留退库行项目是否填完
    public static boolean checkReservedItem(RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean saleRefundStorageItem) {
        if (TextUtils.isEmpty(saleRefundStorageItem.getRefundNumber())) {
            return false;
        } else {
            if (Double.parseDouble(saleRefundStorageItem.getRefundNumber()) == 0) {
                return false;
            }
        }
        if (TextUtils.isEmpty(saleRefundStorageItem.getBatch())) {
            if (saleRefundStorageItem.getBatchList() == null || saleRefundStorageItem.getBatchList().isEmpty()) {
                return false;
            }
        }
        return true;
    }

    //通过领料退库用户组获取领料退库经办人列表
    public static List<GetOperatorBean.OperatorBean> getPickingAddOperatorListByGroupList(Context context, List<GetOperatorGroupBean.OperatorGroupBean> groupListBeanList, String groupCodeStr) {
        List<GetOperatorBean.OperatorBean> list = new ArrayList<>();
        for (int i = 0; i < groupListBeanList.size(); i++) {
            if (groupListBeanList.get(i).getGroup_id().equals(groupCodeStr)) {
                List<GetOperatorBean.OperatorBean> groupList = groupListBeanList.get(i).getGroup_item_list();
                for (int j = 0; j < groupList.size(); j++) {
                    GetOperatorBean.OperatorBean receiverListBean = groupList.get(j);
                    GetOperatorBean.OperatorBean receiveReceiver = new GetOperatorBean.OperatorBean();
                    receiveReceiver.setUser_id(receiverListBean.getUser_id());
                    receiveReceiver.setUser_name(receiverListBean.getUser_name());
                    receiveReceiver.setOrg_name(receiverListBean.getOrg_name());
                    receiveReceiver.setRole_name(receiverListBean.getRole_name());
                    receiveReceiver.setRole_id(receiverListBean.getRole_id());
                    receiveReceiver.setMobile(receiverListBean.getMobile());
                    list.add(receiveReceiver);
                }
            }
        }
        return list;
    }

    //通过销售退库用户组获取销售退库经办人列表
    public static List<GetOperatorBean.OperatorBean> getSaleAddOperatorListByGroupList(Context context, List<GetOperatorGroupBean.OperatorGroupBean> groupListBeanList, String groupCodeStr) {
        List<GetOperatorBean.OperatorBean> list = new ArrayList<>();
        for (int i = 0; i < groupListBeanList.size(); i++) {
            if (groupListBeanList.get(i).getGroup_id().equals(groupCodeStr)) {
                List<GetOperatorBean.OperatorBean> groupList = groupListBeanList.get(i).getGroup_item_list();
                for (int j = 0; j < groupList.size(); j++) {
                    GetOperatorBean.OperatorBean receiverListBean = groupList.get(j);
                    GetOperatorBean.OperatorBean receiveReceiver = new GetOperatorBean.OperatorBean();
                    receiveReceiver.setUser_id(receiverListBean.getUser_id());
                    receiveReceiver.setUser_name(receiverListBean.getUser_name());
                    receiveReceiver.setOrg_name(receiverListBean.getOrg_name());
                    receiveReceiver.setRole_name(receiverListBean.getRole_name());
                    receiveReceiver.setRole_id(receiverListBean.getRole_id());
                    receiveReceiver.setMobile(receiverListBean.getMobile());
                    list.add(receiveReceiver);
                }
            }
        }
        return list;
    }

    //通过预留退库用户组获取销售退库经办人列表
    public static List<GetOperatorBean.OperatorBean> getReservedAddOperatorListByGroupList(Context context, List<GetOperatorGroupBean.OperatorGroupBean> groupListBeanList, String groupCodeStr) {
        List<GetOperatorBean.OperatorBean> list = new ArrayList<>();
        for (int i = 0; i < groupListBeanList.size(); i++) {
            if (groupListBeanList.get(i).getGroup_id().equals(groupCodeStr)) {
                List<GetOperatorBean.OperatorBean> groupList = groupListBeanList.get(i).getGroup_item_list();
                for (int j = 0; j < groupList.size(); j++) {
                    GetOperatorBean.OperatorBean receiverListBean = groupList.get(j);
                    GetOperatorBean.OperatorBean receiveReceiver = new GetOperatorBean.OperatorBean();
                    receiveReceiver.setUser_id(receiverListBean.getUser_id());
                    receiveReceiver.setUser_name(receiverListBean.getUser_name());
                    receiveReceiver.setOrg_name(receiverListBean.getOrg_name());
                    receiveReceiver.setRole_name(receiverListBean.getRole_name());
                    receiveReceiver.setRole_id(receiverListBean.getRole_id());
                    receiveReceiver.setMobile(receiverListBean.getMobile());
                    list.add(receiveReceiver);
                }
            }
        }
        return list;
    }

    //清空原领料退库经办人并添加选择用户组的领料退库经办人人
    public static void addGroupPickingAddOperator(Context context, List<GetOperatorBean.OperatorBean> list) {
        RefundStoragePickingOverviewBean bean = getRefundStoragePickingOverviewBean(context);
        bean.getBody().setUser_list(list);
        savePickingRefundStorageOverviewBean(context, bean);
    }

    //清空原销售退库经办人并添加选择用户组的销售退库经办人人
    public static void addGroupSaleAddOperator(Context context, List<GetOperatorBean.OperatorBean> list) {
        RefundStorageSaleOverviewBean bean = getRefundStorageSaleOverviewBean(context);
        bean.getBody().setUser_list(list);
        saveSaleRefundStorageOverviewBean(context, bean);
    }

    //清空原预留退库经办人并添加选择用户组的预留退库经办人人
    public static void addGroupReservedAddOperator(Context context, List<GetOperatorBean.OperatorBean> list) {
        RefundStorageReservedOverviewBean bean = getRefundStorageReservedOverviewBean(context);
        bean.getBody().setUser_list(list);
        saveReservedRefundStorageOverviewBean(context, bean);
    }

    //判断领料退库是否有经办人员
    public static boolean pickingHasOperator(Context context) {
        List<GetOperatorBean.OperatorBean> operatorList = getRefundStoragePickingOverviewBean(context).getBody().getUser_list();
        if (operatorList != null && !operatorList.isEmpty()) {
            return true;
        }
        return false;
    }

    //判断销售退库是否有经办人员
    public static boolean saleHasOperator(Context context) {
        List<GetOperatorBean.OperatorBean> operatorList = getRefundStorageSaleOverviewBean(context).getBody().getUser_list();
        if (operatorList != null && !operatorList.isEmpty()) {
            return true;
        }
        return false;
    }

    //判断预留退库是否有经办人员
    public static boolean reservedHasOperator(Context context) {
        List<GetOperatorBean.OperatorBean> operatorList = getRefundStorageReservedOverviewBean(context).getBody().getUser_list();
        if (operatorList != null && !operatorList.isEmpty()) {
            return true;
        }
        return false;
    }

    //删除领料退库经办人
    public static void deletePickingOperator(Context context, String id) {
        RefundStoragePickingOverviewBean bean = getRefundStoragePickingOverviewBean(context);
        List<GetOperatorBean.OperatorBean> operatorList = bean.getBody().getUser_list();
        for (int i = 0; i < operatorList.size(); i++) {
            GetOperatorBean.OperatorBean operatorItem = operatorList.get(i);
            if (operatorItem.getUser_id().equals(id)) {
                operatorList.remove(operatorItem);
                break;
            }
        }
        bean.getBody().setUser_list(operatorList);
        savePickingRefundStorageOverviewBean(context, bean);
    }

    //删除销售退库经办人
    public static void deleteSaleOperator(Context context, String id) {
        RefundStorageSaleOverviewBean bean = getRefundStorageSaleOverviewBean(context);
        List<GetOperatorBean.OperatorBean> operatorList = bean.getBody().getUser_list();
        for (int i = 0; i < operatorList.size(); i++) {
            GetOperatorBean.OperatorBean operatorItem = operatorList.get(i);
            if (operatorItem.getUser_id().equals(id)) {
                operatorList.remove(operatorItem);
                break;
            }
        }
        bean.getBody().setUser_list(operatorList);
        saveSaleRefundStorageOverviewBean(context, bean);
    }

    //删除销预留退库经办人
    public static void deleteReservedOperator(Context context, String id) {
        RefundStorageReservedOverviewBean bean = getRefundStorageReservedOverviewBean(context);
        List<GetOperatorBean.OperatorBean> operatorList = bean.getBody().getUser_list();
        for (int i = 0; i < operatorList.size(); i++) {
            GetOperatorBean.OperatorBean operatorItem = operatorList.get(i);
            if (operatorItem.getUser_id().equals(id)) {
                operatorList.remove(operatorItem);
                break;
            }
        }
        bean.getBody().setUser_list(operatorList);
        saveReservedRefundStorageOverviewBean(context, bean);
    }

    //    添加领料退库经办人
    public static void addPickingOperator(Context context, GetOperatorBean.OperatorBean receiveItem) {
        RefundStoragePickingOverviewBean bean = getRefundStoragePickingOverviewBean(context);
        List<GetOperatorBean.OperatorBean> receiverList = bean.getBody().getUser_list() == null ? new ArrayList<>() : bean.getBody().getUser_list();
        receiverList.add(0, receiveItem);
        bean.getBody().setUser_list(receiverList);
        savePickingRefundStorageOverviewBean(context, bean);
    }

    //    添加销售退库经办人
    public static void addSaleOperator(Context context, GetOperatorBean.OperatorBean receiveItem) {
        RefundStorageSaleOverviewBean bean = getRefundStorageSaleOverviewBean(context);
        List<GetOperatorBean.OperatorBean> receiverList = bean.getBody().getUser_list() == null ? new ArrayList<>() : bean.getBody().getUser_list();
        receiverList.add(0, receiveItem);
        bean.getBody().setUser_list(receiverList);
        saveSaleRefundStorageOverviewBean(context, bean);
    }

    //    添加预留退库经办人
    public static void addReservedOperator(Context context, GetOperatorBean.OperatorBean receiveItem) {
        RefundStorageReservedOverviewBean bean = getRefundStorageReservedOverviewBean(context);
        List<GetOperatorBean.OperatorBean> receiverList = bean.getBody().getUser_list() == null ? new ArrayList<>() : bean.getBody().getUser_list();
        receiverList.add(0, receiveItem);
        bean.getBody().setUser_list(receiverList);
        saveReservedRefundStorageOverviewBean(context, bean);
    }

    //拼领料退库对象
    public static RefundStoragePickingConfirmRequestBean getRefundStoragePickingConfirmRequestBean(Context context, String voucherDate, String postDate) {
        RefundStoragePickingConfirmRequestBean result = new RefundStoragePickingConfirmRequestBean();
        RefundStoragePickingOverviewBean bean = RefundStorageUtils.getRefundStoragePickingOverviewBean(context);
        result.setReturn_id(TextUtils.isEmpty(bean.getBody().getRefundStorageNumber()) ? "0" : bean.getBody().getRefundStorageNumber());
        result.setStock_output_id(bean.getBody().getStock_output_code());
//        result.setVoucherDate(voucherDate);
//        result.setPostDate(postDate);
        result.setRemark(bean.getBody().getRemark());
        //操作人
        List<RefundStoragePickingConfirmRequestBean.UserListBean> resultOperatorList = new ArrayList<>();
        List<GetOperatorBean.OperatorBean> operatorList = bean.getBody().getUser_list();
        for (int i = 0; i < operatorList.size(); i++) {
            RefundStoragePickingConfirmRequestBean.UserListBean operator = new RefundStoragePickingConfirmRequestBean.UserListBean();
            operator.setUser_id(operatorList.get(i).getUser_id());
            operator.setRole_id(operatorList.get(i).getRole_id());
            resultOperatorList.add(operator);
        }
        result.setUser_list(resultOperatorList);
        //物料
        List<RefundStoragePickingConfirmRequestBean.ItemListBean> resultMaterielList = new ArrayList<>();
        List<RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean> materielList = bean.getBody().getItem_list();
        for (int i = 0; i < materielList.size(); i++) {
            RefundStoragePickingConfirmRequestBean.ItemListBean resultMateriel = new RefundStoragePickingConfirmRequestBean.ItemListBean();
            RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean materiel = materielList.get(i);
            resultMateriel.setReturn_qty(materiel.getRefundNumber());
            resultMateriel.setRid(materiel.getRid());
            resultMateriel.setStock_output_rid(materiel.getRefundNumber());
            resultMateriel.setBatch(materiel.getBatch());
            if (!TextUtils.isEmpty(resultMateriel.getStock_output_rid()) && !TextUtils.isEmpty(resultMateriel.getBatch())) {
                resultMaterielList.add(resultMateriel);
            }
        }
        result.setItem_list(resultMaterielList);
        return result;
    }

    //拼销售退库对象
    public static RefundStorageSaleConfirmRequestBean getRefundStorageSaleConfirmRequestBean(Context context, String voucherDate, String postDate) {
        RefundStorageSaleConfirmRequestBean result = new RefundStorageSaleConfirmRequestBean();
        RefundStorageSaleOverviewBean bean = RefundStorageUtils.getRefundStorageSaleOverviewBean(context);

        result.setReturn_id(TextUtils.isEmpty(bean.getBody().getRefundStorageNumber()) ? "0" : bean.getBody().getRefundStorageNumber());
        result.setRefer_receipt_code(bean.getBody().getRefer_receipt_code());
//        result.setVoucherDate(voucherDate);
//        result.setPostDate(postDate);
        result.setRemark(bean.getBody().getRemark());
        //操作人
        List<RefundStorageSaleConfirmRequestBean.UserListBean> resultOperatorList = new ArrayList<>();
        List<GetOperatorBean.OperatorBean> operatorList = bean.getBody().getUser_list();
        for (int i = 0; i < operatorList.size(); i++) {
            RefundStorageSaleConfirmRequestBean.UserListBean operator = new RefundStorageSaleConfirmRequestBean.UserListBean();
            operator.setUser_id(operatorList.get(i).getUser_id());
            operator.setRole_id(operatorList.get(i).getRole_id());
            resultOperatorList.add(operator);
        }
        result.setUser_list(resultOperatorList);
        //物料
        List<RefundStorageSaleConfirmRequestBean.ItemListBean> resultMaterielList = new ArrayList<>();
        List<RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean> materielList = bean.getBody().getItem_list();
        for (int i = 0; i < materielList.size(); i++) {
            RefundStorageSaleConfirmRequestBean.ItemListBean resultMateriel = new RefundStorageSaleConfirmRequestBean.ItemListBean();
            RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean materiel = materielList.get(i);
            resultMateriel.setRid(materiel.getRid());
            resultMateriel.setSale_rid(materiel.getSale_rid());
            resultMateriel.setReturn_qty(materiel.getRefundNumber());

            if (!TextUtils.isEmpty(materiel.getBatch())) {
                if (materiel.getBatch().equals(context.getResources().getString(R.string.activity_refund_storage_reserced_materiel_detail_use_the_new_batch))) {
                    int size = Integer.parseInt(materiel.getBatch_material_spec_list_long());
                    List<BatchSpecListBean> list = materiel.getBatchList();
                    List<BatchSpecListBean> batch_material_spec_list = new ArrayList<>();
                    List<BatchSpecListBean> batch_spec_list = new ArrayList<>();
                    for (int j = 0; j < list.size(); j++) {
                        BatchSpecListBean batchSpecListBean = list.get(j);
                        if (j<size) batch_material_spec_list.add(batchSpecListBean);
                        else batch_spec_list.add(batchSpecListBean);
                    }
                    listToRefundStorageSaleConfirmRequestBean(resultMateriel, batch_material_spec_list, true);
                    listToRefundStorageSaleConfirmRequestBean(resultMateriel, batch_spec_list, false);
                    resultMateriel.setBatch("");
                } else {
                    resultMateriel.setBatch_material_spec_list(new ArrayList<>());
                    resultMateriel.setBatch_spec_list(new ArrayList<>());
                    resultMateriel.setBatch(String.valueOf(materiel.getBatch()));
                }
            }
            if (!TextUtils.isEmpty(materiel.getRefundNumber()) && !TextUtils.isEmpty(materiel.getBatch())) {
                resultMaterielList.add(resultMateriel);
            }
        }
        result.setItem_list(resultMaterielList);
        return result;
    }

    private static void listToRefundStorageSaleConfirmRequestBean(RefundStorageSaleConfirmRequestBean.ItemListBean resultMateriel, List<BatchSpecListBean> l, boolean type) {
        List<RefundStorageSaleConfirmRequestBean.ItemListBean.BatchSpecListBean> list = new ArrayList<>();
        for (BatchSpecListBean b : l) {
            RefundStorageSaleConfirmRequestBean.ItemListBean.BatchSpecListBean bean = new RefundStorageSaleConfirmRequestBean.ItemListBean.BatchSpecListBean();
            bean.setBatch_spec_code(b.getBatch_spec_code());
            bean.setBatch_spec_value(b.getText());
            list.add(bean);
        }
        if (type) resultMateriel.setBatch_material_spec_list(list);
        else resultMateriel.setBatch_spec_list(list);
    }

    //拼预留退库对象
    public static RefundStorageReservedConfirmRequestBean getRefundStorageReservedConfirmRequestBean(Context context, String voucherDate, String postDate) {
        RefundStorageReservedConfirmRequestBean result = new RefundStorageReservedConfirmRequestBean();
        RefundStorageReservedOverviewBean bean = RefundStorageUtils.getRefundStorageReservedOverviewBean(context);
        result.setReturn_id(TextUtils.isEmpty(bean.getBody().getRefundStorageNumber()) ? "0" : bean.getBody().getRefundStorageNumber());
        result.setRefer_receipt_code(bean.getBody().getRefer_receipt_code());
//        result.setReserve_cost_obj_code(bean.getBody().getReserve_cost_obj_code());
//        result.setReserve_cost_obj_name(bean.getBody().getReserve_cost_obj_name());
//        result.setVoucherDate(voucherDate);
//        result.setPostDate(postDate);
        result.setRemark(bean.getBody().getRemark());
        //操作人
        List<RefundStorageReservedConfirmRequestBean.UserListBean> resultOperatorList = new ArrayList<>();
        List<GetOperatorBean.OperatorBean> operatorList = bean.getBody().getUser_list();
        for (int i = 0; i < operatorList.size(); i++) {
            RefundStorageReservedConfirmRequestBean.UserListBean operator = new RefundStorageReservedConfirmRequestBean.UserListBean();
            operator.setUser_id(operatorList.get(i).getUser_id());
            operator.setRole_id(operatorList.get(i).getRole_id());
            resultOperatorList.add(operator);
        }
        result.setUser_list(resultOperatorList);
        //物料
        List<RefundStorageReservedConfirmRequestBean.ItemListBean> resultMaterielList = new ArrayList<>();
        List<RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean> materielList = bean.getBody().getItem_list();
        for (int i = 0; i < materielList.size(); i++) {
            RefundStorageReservedConfirmRequestBean.ItemListBean resultMateriel = new RefundStorageReservedConfirmRequestBean.ItemListBean();
            RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean materiel = materielList.get(i);
            resultMateriel.setRid(materiel.getRid());
            resultMateriel.setReturn_qty(materiel.getRefundNumber());
            resultMateriel.setReserve_rid(materiel.getReserve_rid());

            if (!TextUtils.isEmpty(materiel.getBatch())) {
                if (materiel.getBatch().equals(context.getResources().getString(R.string.activity_refund_storage_reserced_materiel_detail_use_the_new_batch))) {
                    int size = Integer.parseInt(materiel.getBatch_material_spec_list_long());

                    List<BatchSpecListBean> list = materiel.getBatchList();
                    List<BatchSpecListBean> batch_material_spec_list = new ArrayList<>();
                    List<BatchSpecListBean> batch_spec_list = new ArrayList<>();
                    for (int j = 0; j < list.size(); j++) {
                        BatchSpecListBean batchSpecListBean = list.get(j);
                        if (j<size) batch_material_spec_list.add(batchSpecListBean);
                        else batch_spec_list.add(batchSpecListBean);
                    }
//                    List<BatchSpecListBean> list = materiel.getBatchList();
//                    List<BatchSpecListBean> batch_material_spec_list = list.subList(0, size - 1);
//                    List<BatchSpecListBean> batch_spec_list = list.subList(size, list.size() - 1);
                    listToRefundStorageReservedConfirmRequestBean(resultMateriel, batch_material_spec_list, true);
                    listToRefundStorageReservedConfirmRequestBean(resultMateriel, batch_spec_list, false);
                    resultMateriel.setBatch("");
                } else {
                    resultMateriel.setBatch_material_spec_list(new ArrayList<>());
                    resultMateriel.setBatch_spec_list(new ArrayList<>());
                    resultMateriel.setBatch(materiel.getBatch());
                }
            }
            if (!TextUtils.isEmpty(materiel.getRefundNumber()) && !TextUtils.isEmpty(materiel.getBatch())) {

                resultMaterielList.add(resultMateriel);
            }
        }
        result.setItem_list(resultMaterielList);
        return result;
    }

    private static void listToRefundStorageReservedConfirmRequestBean(RefundStorageReservedConfirmRequestBean.ItemListBean resultMateriel, List<BatchSpecListBean> l, boolean type) {
        List<RefundStorageReservedConfirmRequestBean.ItemListBean.BatchSpecListBean> list = new ArrayList<>();
        for (BatchSpecListBean b : l) {
            RefundStorageReservedConfirmRequestBean.ItemListBean.BatchSpecListBean bean = new RefundStorageReservedConfirmRequestBean.ItemListBean.BatchSpecListBean();
            bean.setBatch_spec_code(b.getBatch_spec_code());
            bean.setBatch_spec_value(b.getText());
            list.add(bean);
        }
        if (type) resultMateriel.setBatch_material_spec_list(list);
        else resultMateriel.setBatch_spec_list(list);
    }

    public static void updatePickingRefundStorageNumber(Context context, String refundStorageNumber) {
        RefundStoragePickingOverviewBean bean = getRefundStoragePickingOverviewBean(context);
        bean.getBody().setRefundStorageNumber(refundStorageNumber);
        savePickingRefundStorageOverviewBean(context, bean);
    }

    public static void updateSaleRefundStorageNumber(Context context, String refundStorageNumber) {
        RefundStorageSaleOverviewBean bean = getRefundStorageSaleOverviewBean(context);
        bean.getBody().setRefundStorageNumber(refundStorageNumber);
        saveSaleRefundStorageOverviewBean(context, bean);
    }

    public static void updateReservedRefundStorageNumber(Context context, String refundStorageNumber) {
        RefundStorageReservedOverviewBean bean = getRefundStorageReservedOverviewBean(context);
        bean.getBody().setRefundStorageNumber(refundStorageNumber);
        saveReservedRefundStorageOverviewBean(context, bean);
    }

    //通过序号获取领料退库的索引
    public static int getPickingIndexBySerial(Context context, String serialNumber) {
        List<RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean> list = getRefundStoragePickingOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getRid().equals(serialNumber)) {
                return i;
            }
        }
        return -1;
    }

    //通过序号获取销售退库的索引
    public static int getSaleIndexBySerial(Context context, String serialNumber) {
        List<RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean> list = getRefundStorageSaleOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getRid().equals(serialNumber)) {
                return i;
            }
        }
        return -1;
    }

    //通过序号获取预留退库的索引
    public static int getReservedIndexBySerial(Context context, String serialNumber) {
        List<RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean> list = getRefundStorageReservedOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).getRid().equals(serialNumber)) {
                return i;
            }
        }
        return -1;
    }

    //获取领料退库该序号的行项目信息
    public static RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean getPickingMaterielInformationBySerial(Context context, String serialNumber) {
        List<RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean> list = getRefundStoragePickingOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < list.size(); i++) {
            RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean item = list.get(i);
            if (serialNumber.equals(item.getRid())) {
                return item;
            }
        }
        return null;
    }

    //获取销售退库该序号的行项目信息
    public static RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean getSaleMaterielInformationBySerial(Context context, String serialNumber) {
        List<RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean> list = getRefundStorageSaleOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < list.size(); i++) {
            RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean item = list.get(i);
            if (serialNumber.equals(item.getRid())) {
                return item;
            }
        }
        return null;
    }

    //获取预留退库该序号的行项目信息
    public static RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean getReservedMaterielInformationBySerial(Context context, String serialNumber) {
        List<RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean> list = getRefundStorageReservedOverviewBean(context).getBody().getItem_list();
        for (int i = 0; i < list.size(); i++) {
            RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean item = list.get(i);
            if (serialNumber.equals(item.getRid())) {
                return item;
            }
        }
        return null;
    }

    //获取领料退库该索引的行项目信息
    public static RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean getPickingMaterielInformationByIndex(Context context, int index) {
        List<RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean> list = getRefundStoragePickingOverviewBean(context).getBody().getItem_list();
        if (list != null & !list.isEmpty() && list.size() >= index) {
            return list.get(index);
        } else {
            return null;
        }
    }

    //获取销售退库该索引的行项目信息
    public static RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean getSaleMaterielInformationByIndex(Context context, int index) {
        List<RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean> list = getRefundStorageSaleOverviewBean(context).getBody().getItem_list();
        if (list != null & !list.isEmpty() && list.size() >= index) {
            return list.get(index);
        } else {
            return null;
        }
    }

    //获取预留退库该索引的行项目信息
    public static RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean getReservedMaterielInformationByIndex(Context context, int index) {
        List<RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean> list = getRefundStorageReservedOverviewBean(context).getBody().getItem_list();
        if (list != null & !list.isEmpty() && list.size() >= index) {
            return list.get(index);
        } else {
            return null;
        }
    }

    //获取领料退库行项目数量
    public static int getPickingMaterielListSize(Context context) {
        return getRefundStoragePickingOverviewBean(context).getBody().getItem_list().size();
    }

    //获取销售退库行项目数量
    public static int getSaleMaterielListSize(Context context) {
        return getRefundStorageSaleOverviewBean(context).getBody().getItem_list().size();
    }

    //获取预留退库行项目数量
    public static int getReservedMaterielListSize(Context context) {
        return getRefundStorageReservedOverviewBean(context).getBody().getItem_list().size();
    }

    //获取领料退库行项目概览
    public static List<OverviewAdapter.OverviewBean> getOverViewBeanWithPickingRefundStorageList(List<RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean> materielList) {
        List<OverviewAdapter.OverviewBean> resultList = new ArrayList<>();
        for (int i = 0; i < materielList.size(); i++) {
            RefundStoragePickingOverviewBean.OutputInfoBodyBean.ItemListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getRefundNumber())) {
                OverviewAdapter.OverviewBean overItem = new OverviewAdapter.OverviewBean();
                overItem.setInfo(materielItem.getMat_name());
                overItem.setNumber(materielItem.getRefundNumber() + materielItem.getUnit_name());
                resultList.add(overItem);
            }
        }
        return resultList;
    }

    //获取销售退库行项目概览
    public static List<OverviewAdapter.OverviewBean> getOverViewBeanWithSaleRefundStorageList(List<RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean> materielList) {
        List<OverviewAdapter.OverviewBean> resultList = new ArrayList<>();
        for (int i = 0; i < materielList.size(); i++) {
            RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getRefundNumber())) {
                OverviewAdapter.OverviewBean overItem = new OverviewAdapter.OverviewBean();
                overItem.setInfo(materielItem.getMat_name());
                overItem.setNumber(materielItem.getRefundNumber() + materielItem.getUnit_name());
                resultList.add(overItem);
            }
        }
        return resultList;
    }

    //获取预留退库行项目概览
    public static List<OverviewAdapter.OverviewBean> getOverViewBeanWithReservedRefundStorageList(List<RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean> materielList) {
        List<OverviewAdapter.OverviewBean> resultList = new ArrayList<>();
        for (int i = 0; i < materielList.size(); i++) {
            RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean materielItem = materielList.get(i);
            if (!TextUtils.isEmpty(materielItem.getRefundNumber())) {
                OverviewAdapter.OverviewBean overItem = new OverviewAdapter.OverviewBean();
                overItem.setInfo(materielItem.getMat_name());
                overItem.setNumber(materielItem.getRefundNumber() + materielItem.getUnit_name());
                resultList.add(overItem);
            }
        }
        return resultList;
    }

    //创建销售退库下拉选择框
    public static void createNewBatchSelect(Context context, ViewGroup viewGroup, String name, boolean required, String text, String value, List<BatchSpecListBean.InfoBean> selectList, int id) {
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.view_in_storage_textview, null);
        view.setId(id);
        TextView nameTextView = (TextView) view.findViewById(R.id.name);
        TextView textTextView = (TextView) view.findViewById(R.id.text);
        TextView valueTextView = (TextView) view.findViewById(R.id.value);
        if (required) {
            String nameStr = name + "*";
            SpannableStringBuilder builder = new SpannableStringBuilder(nameStr);
            ForegroundColorSpan redSpan = new ForegroundColorSpan(Color.RED);
            builder.setSpan(redSpan, nameStr.length() - 1, nameStr.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            nameTextView.setText(builder);
        } else {
            nameTextView.setText(name);
        }
        textTextView.setText(getNewBatchTextByValue(value, selectList));
        valueTextView.setText(value);
        textTextView.setOnClickListener(new NoDoubleClickListener() {
            @Override
            public void onNoDoubleClick(View v) {
                DialogUtils.getNewBatchSelectDialog(context, selectList, new DialogUtils.SelectListener() {
                    @Override
                    public void onSelect(Dialog dialog, String text, String value) {
                        textTextView.setText(text);
                        valueTextView.setText(value);
                    }
                }).show();
            }
        });
        viewGroup.addView(view);
    }

    private static String getNewBatchTextByValue(String value, List<BatchSpecListBean.InfoBean> selectList) {
        for (int i = 0; i < selectList.size(); i++) {
            BatchSpecListBean.InfoBean selectBean = selectList.get(i);
            if (selectBean.getValue().equals(value)) {
                return selectBean.getText();
            }
        }
        return "";
    }

    //判断新增批次信息必填项是否填完
    public static String newBatchCheck(Context context, List<BatchSpecListBean> list, View dialogView) {
        for (int i = 0; i < list.size(); i++) {
            BatchSpecListBean batchItem = list.get(i);
            String name = batchItem.getBatch_spec_name();
            String type = batchItem.getBatch_spec_type();
            String required = batchItem.getRequired();
            if ("1".equals(required)) {
                View view = dialogView.findViewById(i + 1);
                if ("0".equals(type)) {
                    EditText textEditText = (EditText) view.findViewById(R.id.text);
                    if (TextUtils.isEmpty(textEditText.getText().toString())) {
                        return name + context.getResources().getString(R.string.activity_in_storage_receive_materiel_detail_required_not_null);
                    }
                } else {
                    TextView textTextView = (TextView) view.findViewById(R.id.text);
                    if (TextUtils.isEmpty(textTextView.getText().toString())) {
                        return name + context.getResources().getString(R.string.activity_in_storage_receive_materiel_detail_required_not_null);
                    }
                }
            }
        }
        return null;
    }

    //保存新建批次信息
    public static List<BatchSpecListBean> updateNewBatchInfo(Context context, View view1, String serial, List<BatchSpecListBean> batchBeanList) {
//        materielItem.setRealInStorageNumber(inStorageNumber.getText().toString().replace(materielItem.getUnit(), "").trim());
//        String[] inventoryAddressArray = inventoryAddress.getText().toString().split(" - ");
//        materielItem.setInventoryAddressCode(inventoryAddressArray[0]);
//        materielItem.setInventoryAddressValue(inventoryAddressArray[1]);

//        List<RefundStorageNewBatchBean.DataBean.BatchBean> batchList = new ArrayList<>();
        for (int i = 0; i < batchBeanList.size(); i++) {
            BatchSpecListBean batchItem = batchBeanList.get(i);
            String type = batchItem.getBatch_spec_type();
            View view = view1.findViewById(i + 1);
            switch (type) {
                case "1":
                    batchItem.setText(((EditText) view.findViewById(R.id.text)).getText().toString());
                    break;
                case "2":
                    batchItem.setText(((TextView) view.findViewById(R.id.text)).getText().toString());
                    break;
                case "3":
                    batchItem.setBatch_spec_value(((TextView) view.findViewById(R.id.value)).getText().toString());
                    batchItem.setText(((TextView) view.findViewById(R.id.text)).getText().toString());
                    break;
            }
        }
        return batchBeanList;
    }

    //保存销售出库新建批次信息
    public static void saveNewBatchList(Context context, List<BatchSpecListBean> list, String serial) {
        RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean materielItem = RefundStorageUtils.getSaleMaterielInformationBySerial(context, serial);
        materielItem.setBatchList(list);
        updateSaleRefundStorageItem(context, materielItem);
        LogUtils.i("newBatch ========= " + SPUtils.getSaleRefundStorageInformation(context));
    }

    //保存销售出库新建批次信息
    public static void saveReservedNewBatchList(Context context, List<BatchSpecListBean> list, String serial) {
        RefundStorageReservedOverviewBean.ReservedBodyBean.ItemListBean materielItem = RefundStorageUtils.getReservedMaterielInformationBySerial(context, serial);
        materielItem.setBatchList(list);
        updateReservedRefundStorageItem(context, materielItem);
        LogUtils.i("newBatch ========= " + SPUtils.getReservedRefundStorageInformation(context));
    }

    //获取新建批次信息
    public static List<BatchSpecListBean> getNewBatchInfo(Context context, String serial) {
        RefundStorageSaleOverviewBean.SaleBodyBean.ItemListBean materielItem = RefundStorageUtils.getSaleMaterielInformationBySerial(context, serial);
        return materielItem.getBatchList();
    }
}
